package com.inno.screenrecorder;

import android.content.Context;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.media.projection.MediaProjectionManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;

import com.blankj.utilcode.util.PathUtils;
import com.inno.screenrecordhelper.ScreenRecordManager;

import java.io.IOException;

public class MainActivity3 extends AppCompatActivity {
    private ScreenRecordManager screenRecordHelper = null;
    private AssetFileDescriptor afdd;
    // 音频播放
    private MediaPlayer mediaPlayer = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        init();

        findViewById(R.id.btnStart).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (screenRecordHelper == null) {
                    screenRecordHelper = new ScreenRecordManager(null,MainActivity3.this, new ScreenRecordManager.OnVideoRecordListener() {
                        @Override
                        public void onBeforeRecord() {

                        }

                        @Override
                        public void onStartRecord() {
                        }

                        @Override
                        public void onCancelRecord() {
                        }

                        @Override
                        public void onEndRecord() {
                        }
                    }, PathUtils.getExternalStoragePath() + "/nanchen");

                }
                if (null != screenRecordHelper) {
                    if (!screenRecordHelper.isRecording) {
                        // 如果你想录制音频（一定会有环境音量），你可以打开下面这个限制,并且使用不带参数的 stopRecord()
                        screenRecordHelper.recordAudio = true;
//                        screenRecordHelper.startRecord();
                    }
                }
            }
        });
        findViewById(R.id.btnStop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != screenRecordHelper && screenRecordHelper.isRecording) {
                    screenRecordHelper.stopRecord();
                }
            }
        });
    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
//        screenRecordHelper.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    public void gotoRecord(View view) {
        startActivity(new Intent(this, MainActivity2.class));
    }

}